/******************************init****************************/
function queryPolicySupport(page) {
	var parm = $('#queryPolicySupportForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('policysupport-query');
	sys_record_parm('policysupport',parm);
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#resultList').html(result);
		}
	});
}
function deletePolicySupport(code) {
	$.Zebra_Dialog('是否删除',{
				'type': 'question',
				'title': '警告' ,
				'buttons':[
				           {caption:'删除',callback:function() {
				        	    var url = create_url('policysupport-delete');
						    	policySupport_aidExecute(code, url);
				    		}},
				           {caption:'取消',callback:function(){}
				    	}]
				});
}
function policySupport_aidExecute(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				sys_msg('操作成功');
				queryPolicySupport();
			} else {
				sys_msg('操作失败');
				queryPolicySupport();
			}
		}
	});
}
function topPs(code) {
	$.Zebra_Dialog('是否要置顶',{
					'type': 'question',
					'title': '警告' ,
					'buttons':[
					           {caption:'置顶',callback:function() {
									var url = create_url('policysupport-policysupportTop')
									var parm = {'code':code};
									sys_submiting();
									$.ajax({type:'POST', url:url, data:parm,
										success: function(result) {
											sys_submiting_close();
											if ('success' == result) {
												sys_msg('置顶成功');
												queryOrganActivities();
											} else {
												sys_msg('操作失败');
												queryOrganActivities();
											}
										}
									});
					    		}},
					           {caption:'取消',callback:function(){}
					    	}]
					});
}
/******************************edit****************************/
function savePolicySupport() {
	var parm = $('#editPolicySupportForm').serialize() + '&content=' + fixJqText(Url.encode(content.getData()));
	var url = create_url('policysupport-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
		sys_submiting_close();
			if ('success' == result) {
				sys_msg('操作成功!');
				sys_load_handle('policysupport');
			}
		}
	});
}

function checkedPolicySupport(){
	var title = $("#title").val();
	if(title.length==0){
		sys_msg('必须填写标题');
	}else{
		savePolicySupport();
	}
}

function addFilesUploadEvent_PolicySupport() {
	var url = create_url('policysupport-uploads');
	var btn = $('#uploadFilesBtn1');
	var interval;
	new AjaxUpload(btn, {
		action:url,
		name:'files',
		multiple: true,
		responseType: 'json',
		onSubmit : function(file, ext) {
			if (ext && /^(zip|rar|txt|doc|docx|xls|xlsx|ppt|pptx|pdf|ZIP|RAR|TXT|DOC|DOCX|XLS|XLSX|PPT|PPTX|PDF)$/.test(ext)){
				this.setData({
					'info':'文件类型正确'
				});
			} else {
				sys_msg('文件类型错误', '只能上传类型为：zip、rar、txt、doc、docx、xls、xlsx、ppt、pptx、pdf');
				return false;               
			}
			$('#upload_span').html(sys_loading_img);
			interval = window.setInterval(function () {
                var text = btn.text();
                if (text.length < 10) {
                	btn.text(text + '.');
                } else {
                	btn.text('上传中');
                	this.disable();
                }
            }, 200);
		},
		onComplete: function(files, response){
			window.clearInterval(interval);
			btn.text('[选择]'); 
			if ('error' == response.result){
				sys_msg('失败', '上传文件失败，请检查文件名是否正确!');
			} else if ('file_type_error' == response.result){
				sys_msg('文件类型错误,只能上传类型为：zip、rar、txt、doc、docx、xls、xlsx、ppt、pptx、pdf文件!');
		    } else if('file_size_error' == response.result){
		    	sys_msg('您上传的单个文件必须小于20M');
		    }else {
				var template = $('#tempAnnexListDiv').find('.rep');
				var annexList = $('#annexListTable');
				var index = parseInt($('#workguidedetail_an_index').val());
				$.each(response.list, function(i) {
					var pii = template.clone(true);
					pii.find('.title').html(response.list[i].name + "." +response.list[i].ext).end()
						.find('.name').attr('name', 'List[' + (index) + '].name').val(response.list[i].name).end()
						.find('.size').attr('name', 'List[' + (index) + '].size').val(response.list[i].size).end()
						.find('.sn').attr('name', 'List[' + (index) + '].sn').val(response.list[i].path).end()
						.find('.ext').attr('name', 'List[' + (index) + '].ext').val(response.list[i].ext).end()
						.find('.afcs').val(response.list[i].code).end();
					annexList.append(pii);
					index ++;
					$('#workguidedetail_an_index').val(index);
				});
				this.enable();
				
			}
			
		}
	});
}
function deleteSelectedItem(btn) {
	btn.parents('.rep').remove();
}
/************aidinit******************/

